//
//  HQHotTopView.m
//  MobileiOS
//
//  Created by 郝庆松 on 2018/5/12.
//  Copyright © 2018年 PCITC. All rights reserved.
//

#import "HQHotTopView.h"
#import "HotProductCollCell.h"

@interface HQHotTopView()  <UICollectionViewDataSource, UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@end

@implementation HQHotTopView

+ (instancetype)loadTopHotView{
    return [[[NSBundle mainBundle] loadNibNamed:@"HQHotTopView" owner:nil options:nil] lastObject];
}

- (void)awakeFromNib{
    [super awakeFromNib];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:@"HotProductCollCell" bundle:nil] forCellWithReuseIdentifier:@"HotProductCollCell"];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    _layout.itemSize = CGSizeMake(150 ,self.height - 20);
}

-(void)setDataSource:(NSArray *)dataSource{
    _dataSource = dataSource;
    [self.collectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _dataSource.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HotProductCollCell *cell = [HotProductCollCell cellWithCollectionView:collectionView withIndexPath:indexPath];
    cell.dataInfo = _dataSource[indexPath.row];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [self.delegate selectItem:self withInfo:_dataSource[indexPath.row]];
}

@end
